﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int lowerLimit = int.Parse(LowerLimitTextBox.Text);
            int upperLimit = int.Parse(UpperLimitTextBox.Text);

            List<int> primeNumbers = GetPrimeNumbers(lowerLimit, upperLimit);

            OutputTextBox.Text = "";

            int count = 0;
            foreach (int number in primeNumbers)
            {
                OutputTextBox.Text += number + " ";

                count++;
                if (count % 10 == 0)
                {
                    OutputTextBox.Text += Environment.NewLine;
                }
            }
        }

        private List<int> GetPrimeNumbers(int lowerLimit, int upperLimit)
        {
            List<int> primeNumbers = new List<int>();

            for (int number = lowerLimit; number <= upperLimit; number++)
            {
                if (IsPrime(number))
                {
                    primeNumbers.Add(number);
                }
            }

            return primeNumbers;
        }

        private bool IsPrime(int number)
        {
            if (number < 2)
            {
                return false;
            }

            for (int divisor = 2; divisor <= Math.Sqrt(number); divisor++)
            {
                if (number % divisor == 0)
                {
                    return false;
                }
            }

            return true;
        }

        private void OutputTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}

